package xyz.riceball.exception;

import java.util.Arrays;
import java.util.Collection;

/**
 * <p>
 *
 * </p>
 *
 * @author xiaovcloud
 * @since 2021/7/1 23:03
 */
public class NoUniqueBeanDefinitionException extends RuntimeException {

    private final int numberOfBeansFound;

    private final Collection<String> beanNamesFound;

    public NoUniqueBeanDefinitionException(Class<?> type, int numberOfBeansFound) {
        super("字段" + type.getName() + "没有依赖，没有符合条件的bean类型：预期单个匹配 bean，但发现了" + numberOfBeansFound + "个");
        this.numberOfBeansFound = numberOfBeansFound;
        this.beanNamesFound = null;
    }

    public NoUniqueBeanDefinitionException(Class<?> type, Collection<String> beanNamesFound) {
        super("字段【" + type.getName() + "】没有依赖，没有符合条件的bean类型：预期单个匹配bean，但发现了" + beanNamesFound.size() + "个: " + beanNamesFound);
        this.numberOfBeansFound = beanNamesFound.size();
        this.beanNamesFound = beanNamesFound;
    }

    public NoUniqueBeanDefinitionException(Class<?> type, String... beanNamesFound) {
        this(type, Arrays.asList(beanNamesFound));
    }

    public int getNumberOfBeansFound() {
        return this.numberOfBeansFound;
    }

    public Collection<String> getBeanNamesFound() {
        return this.beanNamesFound;
    }
}
